include( 'file_io.lua' )
include( 'messages.lua' )

if CLIENT then

local gi_Padding = 6
local gi_PreviewTile = 48
local gi_OptionButton = 32
local gi_HotboxCatagoryWide = 100
local gi_PropertyPanelWide = 500
local gi_CatagoryDepth = 1
local gi_HotboxHeight = 200

local WHITE = Color(255,255,255,255)
local ORANGE = Color(195,140,45,255)
local DARK_GREY = Color(16,16,16,255)
local GREY = Color(128,128,128,255)

local function CreateLabel(text, color, parent)
	local label = vgui.Create("DLabel", parent) 
	label:SetText(text) 
	label:SetTextColor(color) 
	label:SizeToContents()
	return label
end

local gLastPropertiesPanel = nil
local CreateListPanel = nil
local gCreateCatagoryPanel = nil
local gCreatePropertiesPanel = nil
local gCurrentCatagoryPanel = nil
local gLastCameraTrackName = "DefaultCamera"
local gLastActorSequencName = "DefaultSequence"
		
function HidePropertiesPanel()
	if gLastPropertiesPanel then
		gLastPropertiesPanel:SetVisible(false)
	end
end

function SwitchToPropertiesPanel(panel)
	if panel then
		HidePropertiesPanel()
		gLastPropertiesPanel = panel
		gLastPropertiesPanel:SetVisible(true)
	end
end

function InitalizeDirectPanel(parent)
	if(parent != nil) then
		if CreateListPanel == nil then
			CreateListPanel = vgui.Create( "DPanel", parent) 
		end
		CreateListPanel:SetParent(parent)
		CreateListPanel:SetSize(gi_HotboxCatagoryWide - gi_Padding, parent:GetTall())
		CreateListPanel:SetPos(0,0)
		CreateListPanel:SetPaintBackground(true)
		InitailizeTypeCatagory(CreateListPanel)

		if gCreateCatagoryPanel == nil then
			gCreateCatagoryPanel = vgui.Create( "DPanel", parent) 
		end
		gCreateCatagoryPanel:SetParent(parent)
		gCreateCatagoryPanel:SetSize(gi_HotboxCatagoryWide - gi_Padding, parent:GetTall())
		gCreateCatagoryPanel:SetPos(gi_HotboxCatagoryWide,0)
		gCreateCatagoryPanel:SetPaintBackground(true)

		if gCreatePropertiesPanel == nil then
			gCreatePropertiesPanel = vgui.Create( "DPanel") 
		end
		gCreatePropertiesPanel:SetParent(parent)
		gCreatePropertiesPanel:SetSize(parent:GetWide() - (2 * gi_HotboxCatagoryWide), parent:GetTall())
		gCreatePropertiesPanel:SetPos(2 * gi_HotboxCatagoryWide,0)
		gCreatePropertiesPanel:SetPaintBackground(true)

		//TEMP: ERASE TO STOP AUTO ENTER
	   //gCurrentCatagoryPanel = SwitchToCatagory(DisplayAnimatedCameraPane(gCreatePropertiesPanel, "Animated Camera"))

	end
end

local PaneCollection = {}
function DisplayRoleplayPane(parent, panelName)

	local tool = nil;
	for _, toolSearch in pairs(LocalPlayer():GetWeapons()) do
		if toolSearch:GetClass() == "interaction" then
			tool = toolSearch
			break
		end
	end

	if tool == nil then	print("Wow - wasn't expecting that (error)") return end

	if PaneCollection[panelName] == nil then
	
		local camPane = vgui.Create( "DPanel", parent) 
		camPane:SetParent(parent)
		camPane:SetSize(parent:GetWide(), parent:GetTall())
		camPane:SetPos(0,0)
		camPane:SetPaintBackground(false)
		camPane:SetVisible(true)
		PaneCollection[panelName] = camPane

		local yPos = gi_Padding - 2;
		local xPos = gi_Padding;
		local cameraSelectionLable = GetTextLabelEx("Roleplay Setup", "Default", camPane)
	
		cameraSelectionLable:SetPos(xPos, yPos)
		yPos = yPos + cameraSelectionLable:GetTall() + gi_Padding
							 
		/***************************************
		 * Define track selection options for 
		 * modifications
		 ***************************************/
		 local trackNameLable = GetTextLabel("Sequence Name:", camPane)
		trackNameLable:SetPos(xPos, yPos)
		yPos = yPos + cameraSelectionLable:GetTall() + gi_Padding
		
		local currentTrackNameValue = nil
		local trackName = vgui.Create( "DTextEntry" ) 
		trackName:SetParent(camPane)
		trackName:SetText( gLastActorSequencName ) 
	   	trackName:SetPos( xPos, yPos) 
		trackName:SetSize( 150, 25 ) 
		trackName.OnEnter = function () 
			gLastCameraTrackName = trackName:GetValue()
			currentTrackNameValue:SetText(gLastActorSequencName)
		end
		local trackSetButton = GetButton("OK", function ()
			gLastActorSequencName = trackName:GetValue()
			currentTrackNameValue:SetText(gLastActorSequencName)
		end, camPane)
		trackSetButton:SetPos(xPos + trackName:GetWide(), yPos)
		trackSetButton:SetSize(30,25)
 		yPos = yPos + trackName:GetTall() + (gi_Padding)
		
		local currentTrackNameLable = GetTextLabel("Current Sequence Name:", camPane)
		currentTrackNameLable:SetPos(xPos, yPos)
		yPos = yPos + currentTrackNameLable:GetTall() + (gi_Padding)

		currentTrackNameValue = GetTextLabelEx(gLastActorSequencName,"Default", camPane)
		currentTrackNameValue:SetColor(Color(140,235,140))
		currentTrackNameValue:SetPos(xPos + 10, yPos)
		yPos = yPos + currentTrackNameValue:GetTall() + (gi_Padding)
		
		local trackNameLabel = GetTextLabel("Note: to create a new actor sequence\nyou must choose a unique name.\nChoosing the name of existing sequence\nwill apply any alterations to that sequence.", camPane)
		trackNameLabel:SetPos(xPos, yPos)
		yPos = yPos + trackNameLabel:GetTall() + gi_Padding


		/***************************************
		 * Define creation controls
		 ***************************************/

		xPos = xPos + (2 * gi_Padding) + 177
		yPos = gi_Padding + cameraSelectionLable:GetTall() + gi_Padding
		GetSeperator(xPos, yPos, 0, camPane:GetTall() - gi_Padding - 30, camPane)
		xPos = xPos + (2 * gi_Padding)
		
		local actor_associated =  GetTextLabel("Actor Sequence Creation:", camPane)
		actor_associated:SetPos(xPos, yPos)
		yPos = yPos + actor_associated:GetTall() + gi_Padding

		begin_camera_create = GetButton("Begin Sequence Creation", function ()
		
			begin_camera_create:SetDisabled(true)
			end_camera_create:SetDisabled(false)

			CloseHotbox()
			local toolStateData = {};
			toolStateData.stateID = "CreateActorSequence"
			datastream.Send("SetToolState", toolStateData)

			local toolCameraData = {};
			toolCameraData.trackID = gLastActorSequencName
			datastream.Send("SetCameraData", toolCameraData)

		end, camPane)

		begin_camera_create:SetPos(xPos,yPos)
		begin_camera_create:SetSize(160,20)

		yPos = yPos + begin_camera_create:GetTall() + gi_Padding
		end_camera_create = GetButton("End Sequence Creation", function ()

			begin_camera_create:SetDisabled(false)
			end_camera_create:SetDisabled(true)

			local weapon = LocalPlayer():GetActiveWeapon();
			local toolStateData = {};
			toolStateData.stateID = "Interact";
			datastream.Send("SetToolState", toolStateData);

		end, camPane)

		begin_camera_create:SetDisabled(false)
		end_camera_create:SetDisabled(true)

		end_camera_create:SetPos(xPos,yPos)
		end_camera_create:SetSize(160,20)

						  
		PaneCollection[panelName].select_actors = select_actors
		PaneCollection[panelName].assocaitedActors = assocaitedActors
	end
	
	

	return PaneCollection[panelName]
end

function DisplayAnimatedCameraPane(parent, panelName)

	if PaneCollection[panelName] == nil then
	
		local camPane = vgui.Create( "DPanel", parent) 
		camPane:SetParent(parent)
		camPane:SetSize(parent:GetWide(), parent:GetTall())
		camPane:SetPos(0,0)
		camPane:SetPaintBackground(false)
		camPane:SetVisible(true)
		PaneCollection[panelName] = camPane

		local yPos = gi_Padding - 2;
		local xPos = gi_Padding;
		local cameraSelectionLable = GetTextLabelEx("Camera Setup", "Default", camPane)
	
		cameraSelectionLable:SetPos(xPos, yPos)
		yPos = yPos + cameraSelectionLable:GetTall() + gi_Padding
							 
		/***************************************
		 * Define track selection options for 
		 * modifications
		 ***************************************/
		 local trackNameLable = GetTextLabel("Camera Track Name:", camPane)
		trackNameLable:SetPos(xPos, yPos)
		yPos = yPos + cameraSelectionLable:GetTall() + gi_Padding
		
		local currentTrackNameValue = nil
		local trackName = vgui.Create( "DTextEntry" ) 
		trackName:SetParent(camPane)
		trackName:SetText( gLastCameraTrackName ) 
	   	trackName:SetPos( xPos, yPos) 
		trackName:SetSize( 150, 25 ) 
		trackName.OnEnter = function () 
			gLastCameraTrackName = trackName:GetValue()
			currentTrackNameValue:SetText(gLastCameraTrackName)
		end
		local trackSetButton = GetButton("OK", function ()
			gLastCameraTrackName = trackName:GetValue()
			currentTrackNameValue:SetText(gLastCameraTrackName)
		end, camPane)
		trackSetButton:SetPos(xPos + trackName:GetWide(), yPos)
		trackSetButton:SetSize(30,25)
 		yPos = yPos + trackName:GetTall() + (gi_Padding)
		
		local currentTrackNameLable = GetTextLabel("Current Track Name:", camPane)
		currentTrackNameLable:SetPos(xPos, yPos)
		yPos = yPos + currentTrackNameLable:GetTall() + (gi_Padding)

		currentTrackNameValue = GetTextLabelEx(gLastCameraTrackName,"Default", camPane)
		currentTrackNameValue:SetColor(Color(140,235,140))
		currentTrackNameValue:SetPos(xPos + 10, yPos)
		yPos = yPos + currentTrackNameValue:GetTall() + (gi_Padding)
		
		local trackNameLabel = GetTextLabel("Note: to create a new camera track\nyou must choose a unique name.\nChoosing the name of existing track\nwill apply any actions to that track.", camPane)
		trackNameLabel:SetPos(xPos, yPos)
		yPos = yPos + trackNameLabel:GetTall() + gi_Padding


		/***************************************
		 * Define creation controls
		 ***************************************/

		xPos = xPos + (2 * gi_Padding) + 177
		yPos = gi_Padding + cameraSelectionLable:GetTall() + gi_Padding

		GetSeperator(xPos, yPos, 0, camPane:GetTall() - gi_Padding - 30, camPane)

		 xPos = xPos + (2 * gi_Padding)
		
		 local create_camera =  GetTextLabel("Creation:", camPane)
		create_camera:SetPos(xPos, yPos)
		yPos = yPos + create_camera:GetTall() + gi_Padding

		local end_camera_create = nil
		local begin_camera_create = nil
		begin_camera_create = GetButton("Begin Camera Creation", function ()
		
			begin_camera_create:SetDisabled(true)
			end_camera_create:SetDisabled(false)

			CloseHotbox()
			local toolStateData = {};
			toolStateData.stateID = "CreateAniCam"
			datastream.Send("SetToolState", toolStateData)

			local toolCameraData = {};
			toolCameraData.trackID = gLastCameraTrackName
			datastream.Send("SetCameraData", toolCameraData)

		end, camPane)

		begin_camera_create:SetPos(xPos,yPos)
		begin_camera_create:SetSize(120,40)

		yPos = yPos + begin_camera_create:GetTall() + gi_Padding
		end_camera_create = GetButton("End Camera Creation", function ()
	

		begin_camera_create:SetDisabled(false)
		end_camera_create:SetDisabled(true)

		local weapon = LocalPlayer():GetActiveWeapon();
		local toolStateData = {};
		toolStateData.stateID = "Interact";
		datastream.Send("SetToolState", toolStateData);

		end, camPane)

		begin_camera_create:SetDisabled(false)
		end_camera_create:SetDisabled(true)

		end_camera_create:SetPos(xPos,yPos)
		end_camera_create:SetSize(120,40)
	end
	
	return PaneCollection[panelName]
end


function DirectPanel(parent)

	local panel = vgui.Create( "DPanel", parent ) 
	panel:SetPos(0,gi_HotboxVerticalAnchor)
	panel:SetSize(parent:GetWide(), parent:GetTall() - 33)

	InitalizeDirectPanel(panel)
	
end	

end //CLIENT